<template>
  <div class="container-content">










    <el-form
      ref="formRef"
      :model="formObject"
      label-width="90px"
      label-position="left"
    >
    <el-collapse v-model="activeNames" @change="handleChange">
  <el-collapse-item title="基本" name="1">
   <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主类型">
              <el-select
                v-model="formObject.kingProfitLossEntity.shipperType"
                placeholder="货主类型"
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option
                  label="业务组织"
                  value="BD_OwnerOrg"
                  checked
                ></el-option>
                <el-option label="供应商组织" value="BD_Supplier"></el-option>
                <el-option label="客户组织" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <!-- <el-input v-model="formObject.kingProfitLossEntity.docTypeCode">
              </el-input> -->
              <el-select
                v-model="formObject.kingProfitLossEntity.type"
                placeholder="单据类型"
                style="width: 100%"
              >
                <el-option label="标准盘盈单" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主">
              <el-input
                v-model="formObject.kingProfitLossEntity.shipperName"
                suffix-icon="el-icon-search"
                @focus="openList('货主')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="formObject.kingProfitLossEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('部门')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('库存组')"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="formObject.kingProfitLossEntity.keeperUserName"
                suffix-icon="el-icon-search"
                @focus="openList('仓管员')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input
                v-model="formObject.kingProfitLossEntity.remarks"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
  </el-collapse-item>
  <el-collapse-item title="其他" name="2">
     <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主类型">
              <el-select
                v-model="formObject.kingProfitLossEntity.shipperType"
                placeholder="货主类型"
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option
                  label="业务组织"
                  value="BD_OwnerOrg"
                  checked
                ></el-option>
                <el-option label="供应商组织" value="BD_Supplier"></el-option>
                <el-option label="客户组织" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <!-- <el-input v-model="formObject.kingProfitLossEntity.docTypeCode">
              </el-input> -->
              <el-select
                v-model="formObject.kingProfitLossEntity.type"
                placeholder="单据类型"
                style="width: 100%"
              >
                <el-option label="标准盘盈单" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主">
              <el-input
                v-model="formObject.kingProfitLossEntity.shipperName"
                suffix-icon="el-icon-search"
                @focus="openList('货主')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="formObject.kingProfitLossEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('部门')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('库存组')"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="formObject.kingProfitLossEntity.keeperUserName"
                suffix-icon="el-icon-search"
                @focus="openList('仓管员')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input
                v-model="formObject.kingProfitLossEntity.remarks"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
  </el-collapse-item>
  <el-collapse-item title="分录明细" name="3">
     <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主类型">
              <el-select
                v-model="formObject.kingProfitLossEntity.shipperType"
                placeholder="货主类型"
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option
                  label="业务组织"
                  value="BD_OwnerOrg"
                  checked
                ></el-option>
                <el-option label="供应商组织" value="BD_Supplier"></el-option>
                <el-option label="客户组织" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <!-- <el-input v-model="formObject.kingProfitLossEntity.docTypeCode">
              </el-input> -->
              <el-select
                v-model="formObject.kingProfitLossEntity.type"
                placeholder="单据类型"
                style="width: 100%"
              >
                <el-option label="标准盘盈单" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主">
              <el-input
                v-model="formObject.kingProfitLossEntity.shipperName"
                suffix-icon="el-icon-search"
                @focus="openList('货主')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="formObject.kingProfitLossEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('部门')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('库存组')"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="formObject.kingProfitLossEntity.keeperUserName"
                suffix-icon="el-icon-search"
                @focus="openList('仓管员')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input
                v-model="formObject.kingProfitLossEntity.remarks"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
  </el-collapse-item>
  <el-collapse-item title="检验结果" name="4">
     <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主类型">
              <el-select
                v-model="formObject.kingProfitLossEntity.shipperType"
                placeholder="货主类型"
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option
                  label="业务组织"
                  value="BD_OwnerOrg"
                  checked
                ></el-option>
                <el-option label="供应商组织" value="BD_Supplier"></el-option>
                <el-option label="客户组织" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <!-- <el-input v-model="formObject.kingProfitLossEntity.docTypeCode">
              </el-input> -->
              <el-select
                v-model="formObject.kingProfitLossEntity.type"
                placeholder="单据类型"
                style="width: 100%"
              >
                <el-option label="标准盘盈单" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主">
              <el-input
                v-model="formObject.kingProfitLossEntity.shipperName"
                suffix-icon="el-icon-search"
                @focus="openList('货主')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="formObject.kingProfitLossEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('部门')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('库存组')"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="formObject.kingProfitLossEntity.keeperUserName"
                suffix-icon="el-icon-search"
                @focus="openList('仓管员')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input
                v-model="formObject.kingProfitLossEntity.remarks"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
  </el-collapse-item>
  <el-collapse-item title="参考" name="5">
     <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主类型">
              <el-select
                v-model="formObject.kingProfitLossEntity.shipperType"
                placeholder="货主类型"
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option
                  label="业务组织"
                  value="BD_OwnerOrg"
                  checked
                ></el-option>
                <el-option label="供应商组织" value="BD_Supplier"></el-option>
                <el-option label="客户组织" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <!-- <el-input v-model="formObject.kingProfitLossEntity.docTypeCode">
              </el-input> -->
              <el-select
                v-model="formObject.kingProfitLossEntity.type"
                placeholder="单据类型"
                style="width: 100%"
              >
                <el-option label="标准盘盈单" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货主">
              <el-input
                v-model="formObject.kingProfitLossEntity.shipperName"
                suffix-icon="el-icon-search"
                @focus="openList('货主')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="formObject.kingProfitLossEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('部门')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="formObject.kingProfitLossEntity.deptName"
                suffix-icon="el-icon-search"
                @focus="openList('库存组')"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="formObject.kingProfitLossEntity.keeperUserName"
                suffix-icon="el-icon-search"
                @focus="openList('仓管员')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input
                v-model="formObject.kingProfitLossEntity.remarks"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
  </el-collapse-item>
</el-collapse>
      <div class="desc-title">分录明细</div>
      <el-table
        :data="formObject.kingProfitLossDetailEntities"
        style="width: 100%"
        highlight-current-row
        border
        :key="flag"
      >
        <template #empty
          ><el-button plain type="primary" round @click="addNewRow"
            >添加新行</el-button
          ></template
        >
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              plain
              icon="el-icon-plus"
              size="small"
              @click="handleDataAdd(scope.$index, scope.row)"
            ></el-button>
            <el-button
              plain
              icon="el-icon-minus"
              size="small"
              @click="handleDataDelete(scope.$index, scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column label="物料编码">
          <template slot-scope="scope">
            <el-input v-model="scope.row.materialCode">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('明细', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            <el-form-item label-width="0px" style="margin: 0">
              <el-input disabled v-model="scope.row.materialName"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.model"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="单位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.purchaseUnitName">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('单位', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="帐存数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="盘点数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.checkNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="盘盈数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.profitLossNum" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓库">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehouseCode">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('仓库', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓位">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.regionName"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="批号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.warehouseId"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="货主">
          <template slot-scope="scope">
            <el-input v-model="scope.row.shipperId" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remarks"> </el-input>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <el-dialog
      width="60%"
      :title="title"
      :visible.sync="dialogTableVisible"
      :append-to-body="appendbody"
    >
      <el-table
        :data="gridData"
         @row-dblclick="getRow"
        v-if="shipper == 'BD_OwnerOrg' && title == '货主'"
      >
        <el-table-column
          property="deptCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="deptName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column property="level" label="形态">
          <!-- 层级(0集团公司 1子公司 2部门) -->
          <template slot-scope="scope">
            <p v-if="scope.row.level == 0">集团公司</p>
            <p v-if="scope.row.level == 1">子公司</p>
            <p v-if="scope.row.level == 2">部门</p>
          </template>
        </el-table-column>
        <el-table-column
          property="parentName"
          label="核算组织"
        ></el-table-column>
        <!-- <el-table-column
          property="address"
          label="核算组织类型"
          width="200"
        ></el-table-column> -->
        <el-table-column
          property="businessDept"
          label="业务组织"
        ></el-table-column>
        <el-table-column property="status" label="组织职能"></el-table-column>
        <el-table-column property="isSend" label="数据状态"></el-table-column>
        <el-table-column property="deptDesc" label="描述"></el-table-column>
        <el-table-column property="leader" label="联系人"></el-table-column>
        <el-table-column property="phone" label="联系电话"></el-table-column>
        <!-- <el-table-column property="address" label="地址"></el-table-column> -->
        <el-table-column property="createBy" label="创建人"></el-table-column>
        <el-table-column
          property="createTime"
          label="创建日期"
        ></el-table-column>
        <!-- <el-table-column property="address" label="修改人"></el-table-column>
        <el-table-column property="address" label="修改日期"></el-table-column> -->
        <!-- <el-table-column property="address" label="禁用状态"></el-table-column>
        <el-table-column property="address" label="禁用人"></el-table-column> -->
      </el-table>
      <el-table
        :data="gridData"
         @row-dblclick="getRow"
        v-if="shipper == 'BD_Supplier' && title == '货主'"
      >
        <el-table-column
          property="supplierCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="supplierName"
          label="名称"
          width="200"
        ></el-table-column>
        <el-table-column property="forShort" label="简称"></el-table-column>
        <el-table-column
          property="supplierGroup"
          label="供应商分组"
        ></el-table-column>
        <el-table-column
          property="examineId"
          label="审核人"
          width="200"
        ></el-table-column>
        <el-table-column
          property="examineTime"
          label="审核日期"
        ></el-table-column>
        <el-table-column
          property="dataState"
          label="数据状态"
        ></el-table-column>
        <el-table-column
          property="disabledState"
          label="禁用状态"
        ></el-table-column>
      </el-table>
      <el-table
        :data="gridData"
         @row-dblclick="getRow"
        v-if="shipper == 'BD_Customer' && title == '货主'"
      >
        <el-table-column
          property="customerCode"
          label="客户编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="customerName"
          label="客户名称"
          width="200"
        ></el-table-column>
        <el-table-column property="abbreviation" label="简称"></el-table-column>
        <el-table-column
          property="supplierGroup"
          label="单据状态"
        ></el-table-column>
        <el-table-column
          property="isUsed"
          label="禁用状态"
          width="200"
        ></el-table-column>
        <el-table-column
          property="examineTime"
          label="审核人"
        ></el-table-column>
        <el-table-column
          property="dataState"
          label="审核日期"
        ></el-table-column>
        <el-table-column
          property="customerGroup"
          label="客户分组"
        ></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '部门'">
        <el-table-column
          property="deptCode"
          label="编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="deptId"
          label="助记码"
          width="200"
        ></el-table-column>
        <el-table-column property="deptName" label="名称"></el-table-column>
        <el-table-column
          property="parentName"
          label="上级部门"
        ></el-table-column>
        <el-table-column
          property=""
          label="HR部门"
          width="200"
        ></el-table-column>
        <el-table-column property="" label="来源于s-HR"></el-table-column>
        <el-table-column property="status" label="数据状态"></el-table-column>
        <el-table-column property="" label="禁用状态"></el-table-column>
        <el-table-column property="deptName" label="部门全称"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '库存组'">
        <el-table-column
          property="date"
          label="业务组编码"
          width="150"
        ></el-table-column>
        <el-table-column
          property="shipperCode"
          label="业务组名称"
          width="200"
        ></el-table-column>
        <el-table-column
          property="address"
          label="业务组类型"
        ></el-table-column>
        <el-table-column property="address" label="启用"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '仓管员'">
        <el-table-column property="nickName" label="名称"></el-table-column>
        <el-table-column property="userCode" label="职员编码"></el-table-column>
        <el-table-column property="deptName" label="部门"></el-table-column>
        <el-table-column property="isUsed" label="禁用状态"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '明细'">
        <el-table-column property="materialCode" label="编码"></el-table-column>
        <el-table-column property="materialName" label="名称"></el-table-column>
        <el-table-column property="model" label="规格型号"></el-table-column>
        <!-- <el-table-column property="isChange" label="数据状态"></el-table-column>
        <el-table-column property="isUsed" label="禁用状态"></el-table-column> -->
        <!-- <el-table-column
          property="materialProperty"
          label="物料属性"
        ></el-table-column> -->
        <el-table-column
          property="purchaseUnitName"
          label="基本单位"
        ></el-table-column>
        <!-- <el-table-column property="isUsed" label="已使用"></el-table-column> -->
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '单位'">
        <el-table-column
          property="meteringUnitCode"
          label="编码"
        ></el-table-column>
        <el-table-column
          property="meteringUnitName"
          label="名称"
        ></el-table-column>
        <el-table-column
          property="isBase"
          label="基准计量单位"
        ></el-table-column>
        <el-table-column property="isUsed" label="数据状态"></el-table-column>
      </el-table>
      <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '仓库'">
        <el-table-column property="wareCode" label="编码"></el-table-column>
        <el-table-column property="wareName" label="名称"></el-table-column>
        <el-table-column property="address" label="仓库地址"></el-table-column>
        <el-table-column
          property="wareManagement"
          label="仓库负责人"
        ></el-table-column>
        <el-table-column property="address" label="仓库属性"></el-table-column>
        <el-table-column
          property="address"
          label="第三方仓储类型"
        ></el-table-column>
        <el-table-column property="" label="数据状态"></el-table-column>
        <el-table-column property="" label="允许即使库负库存"></el-table-column>
        <el-table-column property="" label="启用仓位管理"></el-table-column>
        <el-table-column property="" label="不参与可发量统计"></el-table-column>
        <el-table-column property="" label="参与预警"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogTableVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  addProfitList,
  getdeptList,
  getMaterial,
  getKingBaseMeteringUnitList,
  getWarehouseList,
  getKingBaseBusinessGroupList,
  getKinguserList,
  getSupplierList,
  getCustomerList,
  getregionList,
} from "@/api/bim/bim";
export default {
  data() {
    return {
      activeNames: ['1'],
      shipper: "",
      appendbody: true,
      title: "",
      num: 0,
      flag: false,
      count: 0,
      gridData: [],
      dialogTableVisible: false,
      formObject: {
        kingProfitLossDetailEntities: [],
        kingProfitLossEntity: {
          bizDeptCode: "",
          bizDeptName: "",
          bizTime: "",
          createBy: "",
          createTime: "",
          deptId: "",
          deptName: "",
          docNo: "",
          docTypeCode: "",
          id: "",
          inventoryOrgCode: "",

          keeperUserCode: "",
          pageNo: 0,
          pageSize: 0,
          params: {},
          remark: "",
          remarks: "",
          searchValue: "",
          shipperCode: "",
          shipperType: "",
          type: "",
          updateBy: "",
          updateTime: "",
        },
      },
    };
  },

  methods: {
    selectshipper(val) {
      this.shipper = val;
    },
      handleChange(val) {
        console.log(val);
      },
    // 获取每次点击的内容进行区分，并在此方法内进行打开弹窗及数据的请求
    openList(item, i) {
      this.count = i;
      // console.log(i);
      this.dialogTableVisible = true;
      this.title = item;
      // console.log(item);
      if (this.title == "货主") {
        // 业务组织类型
        if (this.shipper == "BD_OwnerOrg") {
          getdeptList().then((res) => {
            if (res.code == 200) {
              this.gridData = res.data;
            }
          });
          // 供应商组织
        } else if (this.shipper == "BD_Supplier") {
          getSupplierList().then((res) => {
            if (res.code == 200) {
              this.gridData = res.rows;
            }
          });
          // 客户组织
        } else if (this.shipper == "BD_Customer") {
          getCustomerList().then((res) => {
            if (res.code == 200) {
              this.gridData = res.rows;
            }
          });
        }
      } else if (this.title == "部门") {
        getdeptList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.data;
          }
        });
      } else if (this.title == "库存组") {
        this.gridData = [];
      } else if (this.title == "仓管员") {
        getKinguserList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "明细") {
        getMaterial().then((res) => {
          if (res.code == 200) {
            this.gridData = res.data.records;
          }
        });
      } else if (this.title == "单位") {
        getKingBaseMeteringUnitList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "仓库") {
        getWarehouseList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      }
    },
    // 获取点击的表格内容并且关闭弹窗且进行内容的回显
    getRow(row) {
      this.dialogTableVisible = false;
      if (this.title == "货主") {
        if (this.shipper == "BD_OwnerOrg") {
          this.formObject.kingProfitLossEntity.shipperCode = row.businessCode;
          this.formObject.kingProfitLossEntity.shipperName = row.businessName;
          // 供应商组织
        } else if (this.shipper == "BD_Supplier") {
          this.formObject.kingProfitLossEntity.shipperCode = row.supplierCode;
          this.formObject.kingProfitLossEntity.shipperName = row.supplierName;
          // 客户组织
        } else if (this.shipper == "BD_Customer") {
          this.formObject.kingProfitLossEntity.shipperCode = row.customerCode;
          this.formObject.kingProfitLossEntity.shipperName = row.customerName;
        }
      } else if (this.title == "部门") {
        this.formObject.kingProfitLossEntity.deptId = row.bizDeptCode;
        this.formObject.kingProfitLossEntity.deptName = row.deptName;
      } else if (this.title == "库存组") {
        this.formObject.kingProfitLossEntity.inventoryOrgCode =
          row.inventoryOrgCode;
      } else if (this.title == "仓管员") {
        this.formObject.kingProfitLossEntity.keeperUserCode = row.userId;
        this.formObject.kingProfitLossEntity.keeperUserName = row.nickName;
      } else if (this.title == "单位") {
        this.formObject.kingProfitLossDetailEntities[
          this.count
        ].purchaseUnitName = row.meteringUnitName;
        this.formObject.kingProfitLossDetailEntities[this.count].childUnitCode =
          row.meteringUnitCode;
        // this.flag=Math.random()*1000000000000
        this.flag = 2;
      } else if (this.title == "仓库") {
        this.formObject.kingProfitLossDetailEntities[this.count].warehouseCode =
          row.wareCode;
        this.flag = 3;
        getregionList({
          warehouseId: row.id,
        }).then((src) => {
          if (src.code == 200) {
            this.formObject.kingProfitLossDetailEntities[
              this.count
            ].regionName = src.rows[0].regionName;
            this.formObject.kingProfitLossDetailEntities[
              this.count
            ].warehouseId = src.rows[0].warehouseId;
            this.flag = 4;
          }
        });
      } else if (this.title == "明细") {
        this.formObject.kingProfitLossDetailEntities[this.count] = row;
        this.flag = 1;
      }
    },
    selectProject() {},
    handleDataAdd() {
      if (this.formObject.kingProfitLossDetailEntities == undefined) {
        this.formObject.kingProfitLossDetailEntities = [];
      }
      let obj = {
        checkNum: "",
        createBy: "",
        createTime: "",
        id: "",
        inventoryNum: "",

        materialCode: "",
        pageNo: 0,
        pageSize: 0,
        params: {},
        profitLossNum: "",
        relationId: "",
        remark: "",
        remarks: "",
        searchValue: "",
        shipperId: "",
        unit: "",
        updateBy: "",
        updateTime: "",
        warehouseCode: "",
      };
      this.formObject.kingProfitLossDetailEntities.push(obj);
    },
    handleDataDelete(index, row) {
      this.$confirm("请确认是否要删除此行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.formObject.kingProfitLossDetailEntities.splice(index, 1);
          this.num = this.num - 1;
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    addNewRow() {
      this.num = this.num + 1;
      this.handleDataAdd();
    },
    onSubmit() {
      this.formObject.kingProfitLossEntity.id = new Date();
      addProfitList(this.formObject).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: "新增成功！",
            type: "success",
          });
        }
      });
    },
  },
  created() {},
};
</script>

<style lang="scss" scoped>
.divider {
  margin: 0;
}
.el-icon-search {
  margin-top: 70% !important;
}
</style>
